unit MainFm;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ComCtrls, ActnList;

type

  { TMainForm }

  TMainForm = class(TForm)
    ToolButton9: TToolButton;
    TrocarUsuarioAction: TAction;
    SairAction: TAction;
    PrincipalImageList: TImageList;
    SobreAction: TAction;
    PrincipalStatusBar: TStatusBar;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    UsuarioAction: TAction;
    AnaliseAction: TAction;
    LaboratorioAction: TAction;
    TecnicoAction: TAction;
    ProdutorAction: TAction;
    MunicipioAction: TAction;
    PrincipalActionList: TActionList;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    procedure AnaliseActionExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure LaboratorioActionExecute(Sender: TObject);
    procedure MunicipioActionExecute(Sender: TObject);
    procedure ProdutorActionExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SairActionExecute(Sender: TObject);
    procedure SobreActionExecute(Sender: TObject);
    procedure TecnicoActionExecute(Sender: TObject);
    procedure IniciaUsuario(Usuario: string; Tipo: char);
    procedure TrocarUsuarioActionExecute(Sender: TObject);
    procedure UsuarioActionExecute(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  MainForm: TMainForm;

implementation

uses Initializator, MainFr, UsuarioLoginFm;

{ TMainForm }

procedure TMainForm.FormCreate(Sender: TObject);
begin
  // Inicializa os frames
  InitializeFrames();
end;

procedure TMainForm.SairActionExecute(Sender: TObject);
begin
  Close()
end;

procedure TMainForm.SobreActionExecute(Sender: TObject);
begin
  TheControl.ShowFrame(TMainFrame(SobreFrame));
end;

procedure TMainForm.TecnicoActionExecute(Sender: TObject);
begin
  TheControl.ShowFrame(TMainFrame(TecnicoRecordFrame));
end;

procedure TMainForm.IniciaUsuario(Usuario: string; Tipo: char);
begin
  UsuarioAction.Enabled := False;
  LaboratorioAction.Enabled := False;
  TecnicoAction.Enabled := False;
  if (tipo = 'A') then begin
    UsuarioAction.Enabled := True;
  end;
  if (Tipo in ['T', 'A']) then begin
    LaboratorioAction.Enabled := True;
    TecnicoAction.Enabled := True;
  end;
  UsuarioAction.Visible := UsuarioAction.Enabled;
  LaboratorioAction.Visible := LaboratorioAction.Enabled;
  TecnicoAction.Visible := TecnicoAction.Enabled;
  PrincipalStatusBar.Panels.Items[0].Text:='Usuário: ' + Usuario;
end;

procedure TMainForm.TrocarUsuarioActionExecute(Sender: TObject);
begin
  Hide;
  UsuarioLoginForm.Show();
end;

procedure TMainForm.UsuarioActionExecute(Sender: TObject);
begin
  TheControl.ShowFrame(TMainFrame(UsuarioRecordFrame));
end;

procedure TMainForm.ProdutorActionExecute(Sender: TObject);
begin
  TheControl.ShowFrame(TMainFrame(ProdutorRecordFrame));
end;

procedure TMainForm.MunicipioActionExecute(Sender: TObject);
begin
  TheControl.ShowFrame(TMainFrame(MunicipioRecordFrame));
end;

procedure TMainForm.LaboratorioActionExecute(Sender: TObject);
begin
  TheControl.ShowFrame(TMainFrame(LaboratorioRecordFrame));
end;

procedure TMainForm.AnaliseActionExecute(Sender: TObject);
begin
  TheControl.ShowFrame(TMainFrame(AnaliseRecordFrame));
end;

procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  Application.Terminate();
end;

initialization
  {$I mainfm.lrs}

end.

